package com.chw.admin.employee;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chw.utils.CommonFieldsUtil;
import com.chw.utils.UUIDUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class ChwEmployeeService implements IChwEmployeeService {

	@Autowired
	private ChwEmployeeMapper chwEmployeeMapper;

	public PageInfo<ChwEmployee> findByEntity(ChwEmployee chwEmployee, Integer currentPage, Integer pageSize) {
		PageHelper.startPage(currentPage.intValue(), pageSize.intValue());
		List<ChwEmployee> list = this.chwEmployeeMapper.findByEntity(chwEmployee);
		return new PageInfo(list);
	}

	@Override
	public int save(ChwEmployee chwCustomer) {
		// TODO Auto-generated method stub
		try {
			 String status=chwCustomer.getStatus();
			chwCustomer.setEmployeeId(UUIDUtil.getUUID());
			/* 28 */       chwCustomer.setLastUpdatedDate(new Date());
			/* 29 */       chwCustomer.setCreatedDate(new Date());
			/* 30 */       CommonFieldsUtil.setCreateValueByCy(chwCustomer);
			 chwCustomer.setStatus(status);
			chwEmployeeMapper.insert(chwCustomer);
			return 0;	
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return 1;
	}

	@Override
	public int delEmployee(String id) {
		try {
			ChwEmployee chwCustomer=chwEmployeeMapper.selectByPrimaryKey(id);
			chwCustomer.setEnabledFlag("N");
			chwEmployeeMapper.updateByPrimaryKey(chwCustomer);
			return 0;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return 1;
	}

	@Override
	public ChwEmployee findById(String id) {
		// TODO Auto-generated method stub
		return chwEmployeeMapper.selectByPrimaryKey(id);
	}

	@Override
	public int update(ChwEmployee chwCustomer) {
		 try {
			 String status=chwCustomer.getStatus();
			 /* 60 */       CommonFieldsUtil.setCreateValueByCy(chwCustomer);
			 /* 61 */       chwCustomer.setLastUpdatedDate(new Date());
			 chwCustomer.setStatus(status);
			 /* 62 */       this.chwEmployeeMapper.updateByPrimaryKey(chwCustomer);
			 /* 63 */       return 0;
			 /*    */     } catch (Exception e) {
			 /* 65 */       e.printStackTrace();
			 /*    */     }
			 /* 67 */     return 1;
	}

}
